package controller;

import util.SMSUtil;
import Repository.AccountRepository;

public class AccountController extends Controller 
{

	
	private String request;
	private AccountRepository accountRepository = new AccountRepository();
	
	public AccountController (String request)
	{
		this.request = request;
	}

		
	public void handleRequest()
	{
		String choice = null;
		try{
			if (request.toLowerCase().contains("create")){
				do{
					accountRepository.insert();
					System.out.println("Do you wish to create more accounts?(Y/N)");
					choice = SMSUtil.getUserInput();
				}while(choice.trim().equalsIgnoreCase("y"));
			}
			 else if (request.toLowerCase().contains("retrieve"))
				 accountRepository.retrieve(); 
			 else if (request.toLowerCase().contains("update")){
				 do{
					 accountRepository.update(); 
					 System.out.println("Do you wish to update more accounts?(Y/N)");
					choice = SMSUtil.getUserInput();
				}while(choice.trim().equalsIgnoreCase("y"));
			 }
				
			 else if (request.toLowerCase().contains("delete")){
				 do{
					 accountRepository.delete();
					 System.out.println("Do you wish to delete more accounts?(Y/N)");
					choice = SMSUtil.getUserInput();
				}while(choice.trim().equalsIgnoreCase("y"));
			 }
		}catch(NullPointerException ne){
			System.out.println("***Account does not exist***");
		}catch(NumberFormatException ne){
			System.out.println("***Incorrect format***");
		}catch(Exception e){
			System.out.println("***Error!!***");
		}
			 
	}

	
    public Object createAccount()
    {
    	
        return accountRepository.insert();
    }

}